package com.sdp.core.bizc.threadLocal;

public class ContextManager {

	private static final ThreadLocal<ThreadLocalData> localData = new ThreadLocal<ThreadLocalData>()
	{
		@Override
		protected ThreadLocalData initialValue()
		{
			return new ThreadLocalData();
		}
	};
	
	public static ThreadLocalData getLocalData(){		
		return localData.get();
	}
	
	//外部取对象的接口
	
	public static  <T> T getContextData(Class<T> clazz){	
		return getContextData(clazz.getName());
	}
	
	@SuppressWarnings("unchecked")
	public static <T> T getContextData(String key){
		return (T) localData.get().getContextData(key);
	}
	
	//再添加一个put的放对象的接口
	public static <T> void setContextData(Class<T> clazz, Object obj){
		setContextData(clazz.getName(), obj);
	}
	
	public static <T> void setContextData(String key, Object obj){
		localData.get().setContextData(key, obj);
	}
	
	public static void clearContextData(){
		localData.get().clear();
		localData.remove();
	}
}
